package com.rk.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rk.admin.aop.SystemControllerLog;
import com.rk.admin.domain.Resultarticle;
import com.rk.admin.mapper.ResultarticleMapper;
import com.rk.admin.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ResultServiceImpl implements ResultService {
    @Autowired
    private ResultarticleMapper resultarticleMapper;

    /**
     * 添加文章
     * @param resultarticle
     * @return
     */
    @Override
    @SystemControllerLog(description ="添加项目成果文章")
    public Boolean add(Resultarticle resultarticle) {
        return resultarticleMapper.insertResultarticle(resultarticle)>0;
    }


    /**
     * 条件分页查询
     *
     * @param page
     * @param limit
     * @param title
     * @return
     */
    @Override
    public IPage<Resultarticle> selectPage(int page, int limit, String title) {
        IPage<Resultarticle> pageinfo=new Page<>(page,limit);
        LambdaQueryWrapper<Resultarticle> lqw=new LambdaQueryWrapper<Resultarticle>();

        //指定查询字段    id title create
        lqw.select(Resultarticle::getId,Resultarticle::getTitle,Resultarticle::getCreatime,Resultarticle::getModel);


        //通过文章创建时间降序
        lqw.orderByDesc(Resultarticle::getCreatime);

        //根据文章标题进行条件查询
        if(!"".equals(title)&&title!=null){
            lqw.like(Resultarticle::getTitle,title);
        }

        resultarticleMapper.selectPage(pageinfo,lqw);
        return pageinfo;
    }


    /**
     * 通过id删除文章
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteById(Integer id) {
        return resultarticleMapper.deleteById(id)>0;
    }

    /**
     * 通过id修改
     * @param resultarticle
     * @return
     */
    @Override
    public Boolean updatebyId(Resultarticle resultarticle) {

        return resultarticleMapper.updatebyid(resultarticle)>0;
    }

    /**
     * 通过id查找
     *
     * @param id
     * @return
     */
    @Override
    public Resultarticle findbyId(Integer id) {
        return resultarticleMapper.queryById(id);
    }
}
